package com.fnzn.entranceGuard.service.community.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.fnzn.entranceGuard.constant.DeviceTypeContant;
import com.fnzn.entranceGuard.entity.GuardDevice;
import com.fnzn.entranceGuard.entity.sys.SysUserRole;
import com.fnzn.entranceGuard.mapper.community.CommunityInfoMapper;
import com.fnzn.entranceGuard.service.community.ICommunityInfoService;
import com.fnzn.entranceGuard.entity.community.CommunityInfo;
import com.fnzn.entranceGuard.vo.UnitHouseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 小区基本信息表 服务实现类
 * </p>
 *
 * @author xiaosa
 * @since 2018-06-11
 */
@Service
public class CommunityInfoServiceImpl extends ServiceImpl<CommunityInfoMapper, CommunityInfo> implements ICommunityInfoService {

    @Autowired
    private CommunityInfoMapper communityInfoMapper;

    /**
     * 根据当前登录用户id和所属小区id获取到角色id
     *
     * @param username,communityId
     * @return list 角色id集合
     */
    @Override
    public List<SysUserRole> getRoleId(String username, String communityId){

        return communityInfoMapper.getRoleId(username,communityId);
    }

    /**
     * 根据角色id获取到设备集合
     *
     * @param roleId
     * @return list 设备集合
     */
    @Override
    public List<GuardDevice> getDeviceId(String roleId){

        return communityInfoMapper.getDeviceId(roleId);
    }

    @Override
    public List<UnitHouseVo> getHouseByBuilderId(String guardId, String username, String type) {
        List<UnitHouseVo> hosueList = new ArrayList<>();
        if(DeviceTypeContant.BUILDING.equals(type) ){
            hosueList =  communityInfoMapper.getHouseByBuilderId(guardId,username);
        }else if(DeviceTypeContant.unit.equals(type)){
            hosueList =  communityInfoMapper.getHouseByUnitId(guardId,username);
        }
        return hosueList;
    }

    @Override
    public List<SysUserRole> getRoleIdByCompany(String userName, Integer companyId) {
        return communityInfoMapper.getRoleIdByCompany(userName,companyId);
    }

}
